package com.decoration.basic.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

public class ImgUploadUtil {
    //日志输出
    private static Logger logger = LoggerFactory.getLogger(HttpTookit.class);

    //文件上传处理
    public static Integer uploadImg(MultipartFile file,String path,String fileName){
        logger.info("图片上传开始");
        File targetFile = new File(path, fileName);
        if (!targetFile.exists()) {
            targetFile.mkdirs();
        }
        try {
            file.transferTo(targetFile);
        } catch (Exception e) {
            logger.info("图片上传失败"+targetFile);
            e.printStackTrace();
            return 1;
        }
        return 0;
    }

}
